package com.clhbolg.config;

import com.clhbolg.constant.RabbitMQConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author cailinhu
 * @Description TODO
 * @Date 2023/3/1 10:38
 * @Version 1.0
 */
@Configuration
public class RabbitConfig {

    /**
     * json的方式序列号
     *
     * @return
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    /**
     * 注入邮箱mq
     * @return
     */
    @Bean
    public Queue emailQueue() {
        return new Queue(RabbitMQConstant.EMAIL_QUEUE, true);
    }

    @Bean
    public FanoutExchange emailExchange() {
        return new FanoutExchange(RabbitMQConstant.EMAIL_EXCHANGE, true, false);
    }
    @Bean
    public Binding bindingEmailDirect() {
        return BindingBuilder.bind(emailQueue()).to(emailExchange());
    }


}
